package com.daguchuangyi.erp_android.productlist.widget;

import android.content.DialogInterface;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.daguchuangyi.erp_android.R;
import com.jude.utils.JUtils;

/**
 * Created by lijianjian on 2018/3/11.
 */

public class CameralActionDialog extends BaseSlideDialog {

    private TextView mTakePictureTv;
    private TextView mCancelTv;
    private TextView mGalleryTv;

    private OnCameralActionListener mOnCameralActionListener;

    public void setOnCameralActionListener(OnCameralActionListener onCameralActionListener) {
        mOnCameralActionListener = onCameralActionListener;
    }

    @Override
    public int getDialogStyle() {
        return R.style.BottomSlideDialog;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_carmeral_layout;
    }

    @Override
    public void bindView(View v) {
        mCancelTv = (TextView) v.findViewById(R.id.cancel_tv);
        mTakePictureTv = (TextView) v.findViewById(R.id.take_picture_tv);
        mGalleryTv = (TextView) v.findViewById(R.id.gallery_tv);
        mCancelTv.setOnClickListener(view -> {
            if (mOnCameralActionListener != null) {
                mOnCameralActionListener.onCancelClick();
            }
            dismiss();
        });
        mGalleryTv.setOnClickListener(view -> {
            if (mOnCameralActionListener != null) {
                mOnCameralActionListener.onGalleryClick();
            }
            dismiss();
        });
        mTakePictureTv.setOnClickListener(view -> {
            if (mOnCameralActionListener != null) {
                mOnCameralActionListener.onTakePictureClick();
            }
            dismiss();
        });
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        setOnCameralActionListener(null);
        super.onDismiss(dialog);
    }

    @Override
    public int getWidth() {
        return WindowManager.LayoutParams.MATCH_PARENT;
    }

    @Override
    public int getHeight() {
        return JUtils.dip2px(190);
    }

    @Override
    public int getWindowGravity() {
        return Gravity.BOTTOM;
    }

    public interface OnCameralActionListener {
        public void onCancelClick();

        public void onGalleryClick();

        public void onTakePictureClick();
    }
}
